<?php include('scripts.php'); ?>
<script type="text/javascript">

$(function() {
    $("#tradingForm").validate({
        messages : {
            transactionPassword: {
                remote: "Security Password is not valid."
            }
        },
        rules : {
            "transactionPassword" : {
                required : true,
                remote: "/member/verifyTransactionPassword"
            }
        },
        submitHandler: function(form) {
            waiting();
            var buyAmount = $('#reinvestAmount').val();
            var ecashBalance = $('#txtEcash').val();

            if (parseFloat(ecashBalance) < (parseFloat(buyAmount))) {
                alert("<?php echo __("In-sufficient Maintenance Balance")?>");
                return false;
            }

            form.submit();
        }
    });

    $("#btnBuy").button({
        icons: {
            primary: "ui-icon-cart"
        }
    });
})
</script>

<form action="/gold/reinvestCps" id="tradingForm" method="post">
<input type="hidden" name="buyType" value="maintenance">
<div style="padding: 10px; top: 30px; width: 98%">
<div class="portlet">
    <div class="portlet-header"><?php echo __('Reinvest CPS') ?></div>
    <div class="portlet-content">

<table cellpadding="2" cellspacing="5" align="center" border="0" width="70%">
    <tbody>
        <td colspan=2 align='center'>
        <?php if ($sf_flash->has('successMsg')): ?>
            <div class="ui-widget">
                <div style="margin-top: 20px; padding: 0 .7em;" class="ui-state-highlight ui-corner-all">
                    <p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-info"></span>
                    <strong><?php echo $sf_flash->get('successMsg') ?></strong></p>
                </div>
            </div>
        <?php endif; ?>
        <?php if ($sf_flash->has('errorMsg')): ?>
            <div class="ui-widget">
                <div style="margin-top: 20px; padding: 0 .7em;" class="ui-state-error ui-corner-all">
                    <p><span style="float: left; margin-right: .3em;" class="ui-icon ui-icon-alert"></span>
                    <strong><?php echo $sf_flash->get('errorMsg') ?></strong></p>
                </div>
            </div>
        <?php endif; ?>
        </td>

        <tr>
            <td align="right" style="width: 50%; white-space: nowrap;">
                <strong><?php echo __('Maintenance Balance', null, "goldTrading") ?> :</strong>
            </td>
            <td>
                <font color="#61210B">
                    <span id="MyGoldAccount1_Label2">$</span>
                    <span id="spanEcash"><?php echo number_format($maintenance,2)?></span>
                    <input type="hidden" id="txtEcash" value="<?php echo $maintenance?>">
                </font>
            </td>
        </tr>

        <tr>
            <td valign="baseline" align="right">
                <strong><?php echo __('Total CPS reinvest', null, "goldTrading") ?> ：</strong>
            </td>
            <td valign="baseline" align="left">
                <select name="reinvestAmount" id="reinvestAmount">
                    <option value="500">500</option>
                    <option value="1000">1,000</option>
                    <option value="2500">2,500</option>
                    <option value="10000">10,000</option>
                    <option value="15000">15,000</option>
                </select>
            </td>
        </tr>
        <tr>
            <td valign="baseline" align="right">
                <strong><?php echo __('Security Password'); ?> :</strong>
            </td>
            <td valign="baseline" align="left">
                <input name="transactionPassword" type="password" id="transactionPassword" tabindex="2"/>
                <br><br><button id="btnBuy"><?php echo __('Buy', null, "goldTrading") ?></button>
            </td>
        </tr>
        </tbody>
</table>
    </div>
</div>
</div>
</form>